package dp2.tablet.proyecto;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import dp2.tablet.proyecto.bean.*;
import dp2.tablet.proyecto.util.ImageDownloader;

public class EventoAdapter extends BaseAdapter{
	
	List<EventoBean> lista;
	Context context;
	LayoutInflater inflater;
//	private final ImageDownloader imageDownloader = new ImageDownloader();
	
	public EventoAdapter(List<EventoBean> lista, Context context){
		this.lista = lista;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lista.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return lista.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		
		if (convertView == null){
			convertView = inflater.inflate(R.layout.itemevento, null);
			
			holder = new ViewHolder();
			holder.titEvento = (TextView) convertView.findViewById(R.id.titEvento);
			holder.fechaEvento = (TextView) convertView.findViewById(R.id.fechaEvento);
			holder.lugarEvento = (TextView) convertView.findViewById(R.id.lugarEvento);

			
			//holder.imagenPublicitaria = (ImageView) convertView.findViewById(R.id.imgEvento);

//			holder.imagenPublicitaria = (ImageView) convertView.findViewById(R.id.imgEvento);

		
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		EventoBean evento = lista.get(position);
		holder.titEvento.setText(evento.getStrNombre());
		holder.fechaEvento.setText(evento.getFechaEvento());
		holder.lugarEvento.setText(evento.getLugarEvento());

		//imageDownloader.download(evento.getUrlImagen(), holder.imagenPublicitaria);

//		imageDownloader.download(evento.getUrlImagen(), holder.imagenPublicitaria);

		return convertView;
		
	}
	
	class ViewHolder{
		TextView titEvento;
		TextView fechaEvento;
		TextView lugarEvento;

		//ImageView imagenPublicitaria;

//		ImageView imagenPublicitaria;

	}
}
